#include	<stdlib.h>
#include	"my.h"

int		check_nb_redir(t_redir *redir)
{
  int		nb;

  nb = 0;
  nb = redir->left + redir->dleft + redir->right +
    redir->dright;
  return (nb);
}

int		check_redir(char **cmd, t_redir *redir)
{
  int		i;
  int		tot;

  i = 0;
  tot = 0;
  while (cmd[i])
    {
      if (cmd[i][0] == '<' && cmd[i][1] == '\0')
	my_put_nbr(redir->left = 1);
      else if (cmd[i][0] == '<' && cmd[i][1] == '<')
	redir->dleft = 1;
      if (cmd[i][0] == '>' && cmd[i][1] == '>')
	redir->dright = 1;
      if (cmd[i][0] == '>' && cmd[i][1] == '\0')
	my_put_nbr(redir->right = 1);
      i++;
    }
  if ((tot = check_nb_redir(redir)) > 1)
    {
      my_put_error("Ambiguous output redirect\n");
      return (-1);
    }
  return (tot);
}

char		**find_redir(char **cmd, t_redir *redir)
{
  /* if (redir->left == 1 || redir->dleft == 1) */
  /*   //redir_left; */
  if (redir->right == 1 || redir->dright == 1)
    {
     
      cmd = redir_right(1, cmd, redir);
      my_putstr("connard\n");	
    }
  else
    {
      cmd_error(cmd);
      return (NULL);
    }
  return (cmd);
}
